/*********************************************************************************
 *      Copyright:  (C) 2022 Li Yanting<liyanting2@163.com>
 *                  All rights reserved.
 *
 *       Filename:  client_sqlite.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(05/10/2022)
 *         Author:  Li Yanting <liyanting2@163.com>
 *      ChangeLog:  1, Release initial version on "06/22/2022 12:47:46"
 *                 
 ********************************************************************************/

#ifndef _CLIENT_SQLITE_H_
#define _CLIENT_SQLITE_H_

#include <sqlite3.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "get_ctx_conf.h"
#include "logger.h"

#define DATABASE_PATH "../data/data.db"

/*********************************************************************************
 *      Function name:  sql_init
 *        Description:  Init database, include create databases and tables.
 *         @parameter:  db 
 *         @parameter:  table_name  
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int sql_init(sqlite3 **db, char *table_name);


/*********************************************************************************
 *      Function name:  sql_insert
 *        Description:  Insert data into the specified table.
 *         @parameter:  db 
 *         @parameter:  table_name  
 *         @parameter:  format_time  
 *         @parameter:  temper  
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int sql_insert(sqlite3 *db, char *table_name, char *format_time, float temper);


/*********************************************************************************
 *      Function name:  sql_init
 *        Description:  Check whether the specified table has data
 *         @parameter:  db  
 *         @parameter:  st_iotd  Structure receiving data.
 *         @parameter:  table_name  
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int sql_check(sqlite3 *db, iotd_ctx_t *st_iotd, char *table_name);


/*********************************************************************************
 *      Function name:  sql_init
 *        Description:  Delete the first data of the specified table
 *         @parameter:  db 
 *         @parameter:  table_name 
 *       Return value:  On error, -1 is returned. On success, 0 is returned.
 ********************************************************************************/
int sql_delete(sqlite3 *db, char *table_name);

#endif

